package com.agent.course.controller;

import com.agent.commons.Result.Result;
import com.agent.course.service.ClassMemberService;
import com.agent.course.vo.ClassMemberVO;
import com.agent.feign.client.UserClient;
import com.agent.feign.entity.Member;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/member")
public class ClassMemberController {

    @Resource
    private ClassMemberService classMemberService;

    @Resource
    private UserClient userClient;

    /**
     * 获取班级成员信息
     */
    @GetMapping("/get/{classId}")
    public Result<ClassMemberVO> getClassMember(@PathVariable String classId){
        List<String> userIds = classMemberService.getUserIds(classId);
        ClassMemberVO classMemberVO = new ClassMemberVO();
        classMemberVO.setClassId(classId);
        List<Member> members =new ArrayList<>();
        userIds.forEach(userId -> {
            Member member = userClient.getMember(userId);
            members.add(member);
        });
        classMemberVO.setMember(members);
        return Result.success(classMemberVO);
    }
}
